<template>
    <div class="header">

      <router-link tag="div" to="/" class="header-abs iconfont" v-show="showAbs">&#xe624;</router-link>

      <div class="header-fixed"  v-show="!showAbs" :style="opacityStyle">
        <div class="header-back">
          <router-link tag="div" to="/" class="iconfont back-icon">&#xe624;</router-link>
        </div>
        <div class="header-title">{{signtName}}</div>
      </div>
    </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  props: {
    signtName: String
  },
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        let opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import '~css/varibles.styl'
  .header-abs
    position :absolute
    left: .2rem
    top: .2rem
    width: .8rem
    height: .8rem
    border-radius :50%
    background :rgba(0,0,0,.4)
    line-height: .8rem
    text-align :center
    color :#fff
  .header-fixed
    width: 100%
    font-size :0.3rem
    height: $headerHeight
    background: $bgColor
    line-height $headerHeight
    color: #fff
    position :fixed
    top: 0
    left: 0
    z-index :2
    .header-back
      width: 0.64rem
      position :absolute
      left: .2rem
      top: 0
      .back-icon
        text-align :center
    .header-title
      margin-left: .1rem
      text-align :center
</style>
